package com.dlc.commonlibrary.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import com.dlc.commonlibrary.R;
import com.dlc.commonlibrary.utils.ToastUtil;
import com.vector.update_app.UpdateAppBean;
import com.vector.update_app.UpdateAppManager;
import com.zzhoujay.richtext.RichText;

/**
 * Created by Administrator on 2018/10/26/026.
 */

public class UpdateDialog extends Dialog {
    public UpdateDialog(@NonNull
    final Context context, UpdateAppBean updateApp, final UpdateAppManager updateAppManager) {
        super(context, R.style.CommonDialogStyle);
        setContentView(R.layout.dialog_update);
        Window window = this.getWindow();
        window.setGravity(Gravity.CENTER);
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        WindowManager.LayoutParams params = window.getAttributes();
        //params.width = (int) (window.getWindowManager().getDefaultDisplay().getWidth() * 0.9);
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);
        TextView tvDescribe = (TextView) findViewById(R.id.tv_describe);
        RichText.initCacheDir(context);
        RichText.from(updateApp.getUpdateLog()).bind(context).into(tvDescribe);

        TextView tvUpdate = (TextView) findViewById(R.id.tv_to_update);
        tvUpdate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                updateAppManager.download();
                ToastUtil.show(context,"正在下載,請稍後...");
                dismiss();
            }
        } );

    }
}
